package com.quartet.modules.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.system.dao.DictDetailDao;
import com.quartet.modules.system.domain.DictDetail;
import com.quartet.modules.system.domain.DictDetailPs;
import com.quartet.modules.system.service.DictDetailServicePs;
import com.quartet.utils.LocaleUtils;
import com.quartet.utils.constant.MapServerConstant;
import org.springframework.stereotype.Service;

import java.util.Locale;

@Service
public class DictDetailServicePsImpl extends ServiceImpl<DictDetailDao, DictDetailPs> implements DictDetailServicePs {

    @Override
    public String getLabelByValueByCode(String value) {
        QueryWrapper<DictDetailPs> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DictDetailPs::getValue, value);
        DictDetailPs dictDetailPs = this.baseMapper.selectOne(queryWrapper);
        if (ObjectUtil.isEmpty(dictDetailPs)) {
            return "";
        }
        if (LocaleUtils.getLocale().startsWith(MapServerConstant.EN)) {
            return dictDetailPs.getLabelEn();
        } else {
            return dictDetailPs.getLabel();
        }
    }

    @Override
    public String getLabelByValueByCodeAndName(String value, String name) {
        DictDetailPs dictDetailPs = this.baseMapper.getLabelByValueByCodeAndPid(value, name);
        if (LocaleUtils.getLocale().startsWith(MapServerConstant.EN)) {
            return dictDetailPs.getLabelEn();
        } else {
            return dictDetailPs.getLabel();
        }
    }
}
